package web.suzy.oj.controller.file;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.service.file.ProblemFileService;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * YangSuzy 软件工作室
 * 类名: ProblemFileController
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/12/2 23:48
 */
@Controller
@RequestMapping("/api/file")
public class ProblemFileController {
    @Autowired
    private ProblemFileService problemFileService;

    /**
     * 方法名: importProblem
     * 描述: 通过zip文件导入题目
     *
     * @param file 通过zip文件导入题目
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/12/2 23:49
     * @auther YangSuzy
     **/
    @RequiresRoles("root")
    @RequiresAuthentication
    @ResponseBody
    @PostMapping("/import-problem")
    public ResultBean<Void> importProblem(@RequestParam("file") MultipartFile file) {
        return problemFileService.importProblem(file);
    }

    /**
     * 方法名: exportProblem
     * 描述: 导出指定题目和相关测试用例为zip文件
     *
     * @param pidList  题目ID列表
     * @param response 响应
     * @return void
     * @date 2022/12/3 23:46
     * @auther YangSuzy
     **/
    @GetMapping("/export-problem")
    @RequiresAuthentication
    @RequiresRoles("root")
    public void exportProblem(@RequestParam("pid") List<Long> pidList, HttpServletResponse response) {
        problemFileService.exportProblem(pidList, response);
    }
}
